home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / Technical Documentation / develop / develop Issue 23 / develop Issue 23 code / ProjectDrag 1.1b8 / Sources / ProjectDrag Sources / CheckIn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-07  |  5.3 KB  |  199 lines  |  [TEXT/MPS ]

  1. /* CheckIn.c: CheckIn applet for ProjectDrag
  2.  *
  3.  * A set of applets for drag and drop source control by Tim Maroney.
  4.  * See develop, issue 23 for details.
  5.  *
  6.  * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
  7.  * and using the MoreFiles utilities by Jim Luther.
  8.  *
  9.  * This software is free, but don't modify and redistribute it without
  10.  * changing the status window to indicate your name and your changes!
  11.  */
  12.  
  13.  
  14. #include <Errors.h>
  15.  
  16. #include "DSUserProcs.h"
  17. #include "SourceServer.h"
  18. #include "PDDialogs.h"
  19. #include "Comments.h"
  20. #include "TasksAndErrors.h"
  21.  
  22.  
  23. void CheckInFile(FSSpec *file, Boolean doingFolder);
  24.  
  25.  
  26. /* This routine is called for each file passed in the ODOC event. */
  27.  
  28. pascal void OpenDoc ( FSSpecPtr myFSSPtr, Boolean opening, Handle userDataHandle )
  29. {
  30. #pragma unused ( opening )
  31. #pragma unused ( userDataHandle )
  32.  
  33.     ProcessFileOrFolder(myFSSPtr, CheckInFile, ProcessFolder);
  34.     PopAllTasks();
  35. }
  36.  
  37.  
  38. void CheckInFile(FSSpec *file, Boolean doingFolder)
  39. {
  40.     Str63 userName;
  41.     Str15 nickname;
  42.     Str255 comment;
  43.     AEDesc command;
  44.     Str255 projectName;
  45.     OSErr err;
  46.     CKIDHandle theCKID;
  47.     short oldLabel;
  48.         
  49.     /* find the user name and initials */
  50.     err = GetUserSettings(userName, nickname, false);
  51.     if (err != noErr)
  52.     {
  53.         gDone = true;
  54.         return;
  55.     }
  56.  
  57.     /* get the CKID */
  58.     TaskStart(2001, 2, file->name, NULL, NULL, NULL); /* inspecting */
  59.     err = ExtractCKID(file, &theCKID);
  60.     TaskDone();
  61.     if (err != noErr)
  62.     {
  63.         /* add new file to project */
  64.         
  65.         TaskStart(2001, 3, file->name, NULL, NULL, NULL); /* adding */
  66.         
  67.         /* confirm the add */
  68.         if (!ResTextYesNo(kProjectDragStrings, kConfirmAddFile, file->name, NULL, NULL, NULL))
  69.         {
  70.             RaiseErrorNumber(userCanceledErr);
  71.             return;
  72.         }
  73.         
  74.         /* mount the project */
  75.         err = MountProjectFromFolder(file->vRefNum, file->parID, projectName);
  76.         if (err != noErr) return;
  77.  
  78.         /* get the checkin comment from the user */
  79.         GetIndString(comment, kProjectDragStrings, kFirstCheckedIn);
  80.         if (!GetChangeComment(true, file->name, comment))
  81.             return;
  82.  
  83.         /* add the "first checked in" change comment and header */
  84.         err = AddFirstTimeHeader(file, userName, nickname, comment);
  85.         if (err != noErr) return;
  86.         
  87.         /* create a CheckIn command for SourceServer
  88.          * CheckIn -new -cs <comment> -project <project> -u <user> <file>
  89.          */
  90.         err = CreateCommand(&command, "CheckIn");
  91.         if (err == noErr)
  92.             err = AddCStringArg(&command, "-new");
  93.         if (err == noErr)
  94.             err = AddCommentArg(&command, comment);
  95.         if (err == noErr)
  96.             err = AddProjectArg(&command, projectName);
  97.         if (err == noErr)
  98.             err = AddUserArg(&command, userName);
  99.         if (err == noErr)
  100.             err = AddFileNameArg(&command, file);
  101.         if (err != noErr)
  102.         {
  103.             AEDisposeDesc(&command);
  104.             RaiseErrorNumber(err);
  105.             return;
  106.         }
  107.     }
  108.     else
  109.     {
  110.         /* Make sure the file is writeable.
  111.          * If the user dragged a folder, don't complain about all the errors!
  112.          * Just check in the ones that are OK to check in.
  113.          */
  114.         
  115.         TaskStart(2001, 1, file->name, NULL, NULL, NULL); /* checking in */
  116.         
  117.         if (!(*theCKID)->writeable && !(*theCKID)->modifyReadOnly)
  118.         {
  119.             DisposeHandle((Handle)theCKID);
  120.             if (!doingFolder)
  121.                 RaiseErrorString(kProjectDragStrings, kNoCheckInPermission,
  122.                                  file->name, NULL, NULL, NULL);
  123.             else
  124.                 TaskDone(); /* so the task block gets discarded */
  125.             return;
  126.         }
  127.  
  128.         /* XXX see if the version numbers match; if not, refuse to check in */
  129.         
  130.         /* XXX see if the modification date has changed; if not, put up an alert,
  131.          * and if the user confirms, bump the mod date to avoid an error
  132.          */
  133.     
  134.         /* extract the checkout comment from the CKID */
  135.         {
  136.             StringPtr s = (*theCKID)->projectPath; /* careful -- not locked down */
  137.             s += s[0] + 2;        /* skip the project name and null character */
  138.             s += s[0] + 2;        /* skip the user name and null character */
  139.             s += s[0] + 2;        /* skip the revision number and null character */
  140.             s += s[0] + 2;        /* skip the file name and null character */
  141.             if (s[0] == 0)        /* seems to put three chars in null string.... */
  142.                 s += 3;            /* skip the task and null character */
  143.             else
  144.                 s += s[0] + 2;    /* skip the task and null character */
  145.             BlockMove(s, comment, s[0] + 1); /* copy the comment */
  146.         }
  147.         
  148.         /* add the change comment to the file header */
  149.         err = AddCheckinComment(file, userName, nickname, comment);
  150.         if (err != noErr)
  151.         {
  152.             DisposeHandle((Handle)theCKID);
  153.             return;
  154.         }
  155.         
  156.         /* mount the project */
  157.         err = MountProjectFromCKID(theCKID, projectName);
  158.         DisposeHandle((Handle)theCKID);
  159.         if (err != noErr) return;
  160.         
  161.         /* create a CheckIn command for SourceServer
  162.          * CheckIn -cs <comment> -project <project> -u <user> <file>
  163.          */
  164.         err = CreateCommand(&command, "CheckIn");
  165.         if (err == noErr)
  166.             err = AddCommentArg(&command, comment);
  167.         if (err == noErr)
  168.             err = AddProjectArg(&command, projectName);
  169.         if (err == noErr)
  170.             err = AddUserArg(&command, userName);
  171.         if (err == noErr)
  172.             err = AddFileNameArg(&command, file);
  173.         if (err != noErr)
  174.         {
  175.             AEDisposeDesc(&command);
  176.             RaiseErrorNumber(err);
  177.             return;
  178.         }
  179.     }
  180.     
  181.     /* modify the label to red (6) */
  182.     SetFileLabel(file, 6, &oldLabel);
  183.     
  184.     err = SendCommand(&command);        /* send the command to SourceServer */
  185.     if (err == noErr)
  186.         TaskDone();
  187.     else
  188.         SetFileLabel(file, oldLabel, NULL);
  189. }
  190.  
  191.  
  192. void DoFileMenu(short itemID)
  193. {
  194.     if ( itemID == 1 )
  195.         SelectFile();        // call file selection userProc
  196.     else
  197.         SendQuitToSelf();    // send self a 'quit' event
  198. }
  199.